#!/bin/sh
#
# /etc/rc.d/rc.fail2ban
#
# start/stop/reload/status/ping fail2ban server.
#
# To start fail2ban automatically at boot, make this
# file executable:  chmod 755 /etc/rc.d/rc.fail2ban
# you must also add this file to rc.local in the
# appropriate order.

SOCKET="/var/run/fail2ban/fail2ban.socket"

fail2ban_start() {
  if [ -x /etc/rc.d/rc.fail2ban ]; then
	echo "Starting fail2ban: "
	/usr/bin/fail2ban-client -x -s ${SOCKET} start
  else
  	echo "rc.fail2ban is not executable or you don't have enough permissions"
  	exit 1
  fi
}

fail2ban_stop() {
	echo "Stopping fail2ban"
	/usr/bin/fail2ban-client -x -s ${SOCKET} stop
}

fail2ban_reload() {
	echo "Reloading fail2ban"
	/usr/bin/fail2ban-client -x -s ${SOCKET} reload
}

fail2ban_status() {
	echo "Status: fail2ban"
	/usr/bin/fail2ban-client -s ${SOCKET} status
}

fail2ban_ping() {
	echo "Pinging fail2ban"
	/usr/bin/fail2ban-client -s ${SOCKET} ping
}

case "$1" in
'start')
	fail2ban_start
  ;;
'stop')
	fail2ban_stop
  ;;
'restart')
	fail2ban_stop
	sleep 2
	fail2ban_start
;;
'reload')
	fail2ban_reload
  ;;
'status')
	fail2ban_status
  ;;
'ping')
	fail2ban_ping
  ;;
*)
	echo "USAGE: $0 start|stop|restart|reload|status|ping"
	exit 1
  ;;
esac
